﻿using wt.wine.Application.Common.Interfaces;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace wt.wine.Infrastructure.Services
{
    public class CurrentUserService : ICurrentUserService
    {
        private readonly IHttpContextAccessor _httpContextAccessor;

        public CurrentUserService(IHttpContextAccessor httpContextAccessor)
        {
            _httpContextAccessor = httpContextAccessor;
        }

        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <returns></returns>
        public int GetUserId()
        {
            var Id = _httpContextAccessor.HttpContext.User.FindFirst("id");
            return Id?.Value != null ? Convert.ToInt32(Id.Value) : 0;
        }

        /// <summary>
        /// 获取角色id
        /// </summary>
        /// <returns></returns>
        public int GetRoleId()
        {
            var roleid = _httpContextAccessor.HttpContext.User.FindFirst("roleid");
            return roleid?.Value != null ? Convert.ToInt32(roleid.Value) : 0;
        }


        public int GetRoletype() {
            var roletype = _httpContextAccessor.HttpContext.User.FindFirst("roletype");
            return roletype?.Value != null ? Convert.ToInt32(roletype.Value) : 0;
        }
    }
}

